package com.gtxc.kotlinmvvm.ui.activity;

import android.os.Build;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.aleyn.mvvm.base.BaseFragment;

import com.gtxc.kotlinmvvm.BR;
import com.gtxc.kotlinmvvm.R;
import com.gtxc.kotlinmvvm.databinding.ActivityMembeBinding;
import com.gtxc.kotlinmvvm.network.CommonBaseActivity;
import com.gtxc.kotlinmvvm.ui.fragment.LoginFragment;
import com.gtxc.kotlinmvvm.ui.fragment.RegisterFragment;
import com.gtxc.kotlinmvvm.viewmodle.BTViewModle;

import java.util.ArrayList;
import java.util.List;

public class BTLoginActivity extends CommonBaseActivity<BTViewModle, ActivityMembeBinding>{
    private ViewPagerAdapter viewPagerAdapter;
    private int a=1;
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void bindViewModel() {
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        getMBinding().viewPager.setAdapter(viewPagerAdapter);
        getMBinding().viewPager.setCurrentItem(a);
        getMBinding().viewPager. setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                Log.i("TAG", "initViessswq: "+position);
//                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//
//                lp.setMargins(2, 2, 2, 2);
//
////view要设置margin的view
//
//                view.setLayoutParams(lp);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        getMBinding().tabLayout.setTabTextColors(BTLoginActivity.this.getColor(R.color.colorDivider), BTLoginActivity.this.getColor(R.color.colorWhite));
        getMBinding().tabLayout.setSelectedTabIndicatorHeight(0);
        getMBinding().tabLayout.setupWithViewPager(getMBinding().viewPager);
    }
    @Override
    public void initData() {

    }

    @Override
    public void initCLick() {

    }

    @Override
    public int variableID() {
        return BR.BTViewModle;
    }

    @Override
    public int layoutId() {
        return R.layout.activity_membe;
    }


    public static class ViewPagerAdapter extends FragmentPagerAdapter {
        private List<String> titles = new ArrayList<String>();
        private List<BaseFragment> fragments = new ArrayList<>();
        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);

            titles.add("注册");
            titles.add("登录");
            fragments.add(new RegisterFragment());
            fragments.add(new LoginFragment());
        }

        @Override
        public Fragment getItem(int position) {
            Log.i("TAG", "initViewb: "+position);
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return titles.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            Log.i("TAG", "initViewb: "+position);
            return titles.get(position);
        }
    }
}
